package com.koo.modules.sale.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.sale.dao.SaleOrderDetailDao;
import com.koo.modules.sale.entity.SaleOrderDetailEntity;
import com.koo.modules.sale.service.SaleOrderDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class SaleOrderDetailServiceImpl extends ServiceImpl<SaleOrderDetailDao, SaleOrderDetailEntity> implements SaleOrderDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<SaleOrderDetailEntity> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.like(MyStrUtil.isNotEmpty(key), SaleOrderDetailEntity::getName, key)
//                  .or().eq(MyStrUtil.isNotEmpty(key), SaleOrderDetailEntity::getCode, key);

        IPage<SaleOrderDetailEntity> page = this.page(
                new Query<SaleOrderDetailEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<SaleOrderDetailEntity> listByStoreId(Long storeId) {
        LambdaQueryWrapper<SaleOrderDetailEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MyStrUtil.isNotEmpty(storeId), SaleOrderDetailEntity::getStoreId, storeId);
        return this.list(wrapper);
    }

    @Override
    public List<SaleOrderDetailEntity> listByOrderId(String saleId) {
        LambdaQueryWrapper<SaleOrderDetailEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MyStrUtil.isNotEmpty(saleId), SaleOrderDetailEntity::getSaleId, saleId);
        return this.list(wrapper);
    }
}